package com.ruoyi.pdf.receipt;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ruoyi.labsafety.domain.LabSafetyCheckTask;
import com.ruoyi.labsafety.service.ILabSafetyCheckTaskService;
import com.ruoyi.pdf.PdfGenerateServiceImpl;
import com.ruoyi.system.service.ISysDeptService;

@Component
public class PdfGeneratorSafetyCorrective implements PdfGenerator {

    public String getFileName(Long instanceId){
    	return "实验室安全整改通知书("+instanceId+")";
    }
	@Autowired
    private PdfGenerateServiceImpl pdfGenerateService;
	
   @Autowired
   private ILabSafetyCheckTaskService labSafetyCheckTaskService;
   @Autowired
   private ISysDeptService deptService;
    public void run(Long instanceId) throws Exception {
    	
    	Map<String, Object> data = new HashMap<>();
    	//SysDictData queryDict = new SysDictData();
    	//queryDict.setDictType("unitOpt");
    	String users = labSafetyCheckTaskService.selectCheckerNames(instanceId);
    	
    	LabSafetyCheckTask form = labSafetyCheckTaskService.selectLabSafetyCheckTaskById(instanceId);
    	data.put("form", form);
    	
    	data.put("users", users==null?form.getCheckUserName():users);
    	if(form.getCorrectiveMark()!=null){
    		data.put("correctiveMark", form.getCorrectiveMark().replaceAll("\n", "<br/>"));	
    	}
    	data.put("deptName", deptService.selectDeptById(form.getOrgId()).getDeptName());
        pdfGenerateService.generatePdfFile("safety_corrective", data, getFileName(instanceId)+".pdf");
    }
}
